﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace Ex3StudentNameComparator
{
    static class StudentExtension
    {
        public static IEnumerable<Student> GetStudents(this IEnumerable<Student> students)
        {
            var result =
                from student in students
                where student.FirstName.CompareTo(student.SecondName) == -1
                select student;
            return result;
        }

        public static IEnumerable<Student> GetCoolAged(this IEnumerable<Student> students)
        {
            var result =
                from student in students
                where student.Age <= 24 && student.Age >= 18
                select student;
            return result;
        }


        static void Main()
        {
            List<Student> students = new List<Student>();
            students.Add(new Student("marin", "atanasov",22));
            students.Add(new Student("pesho", "subev",33));
            students.Add(new Student("pesho", "ivanchev", 33));

            foreach (var perfectStudent in students.GetStudents())
            {
                Console.WriteLine("Correct Name order ->"+perfectStudent);
            }
            foreach (var perfectStudent in students.GetCoolAged())
            {
                Console.WriteLine("Correct age range ->" + perfectStudent);
            }

            var sortedStudentByName = students.OrderBy(x => x.FirstName).ThenBy(x => x.SecondName);//Ex 5
            var result =
                from student in students
                orderby student.FirstName, student.SecondName //Ex5 second way
                select student;

            result.ToList().ForEach(x => Console.WriteLine(x));
            
        }
    }

    class Student
    {
        private string firstName;
        private string secondName;
        private int age;



        public Student(string firstName, string secondName,int age)
        {
            this.firstName = firstName;
            this.secondName = secondName;
            this.age = age;
        }

        public int Age
        {
            get
            {
                return age;
            }
            set
            {
                age = value;
            }
        }

        public string FirstName
        {
            get
            {
                return firstName;
            }
            set
            {
                firstName = value;
            }
        }

        public string SecondName
        {
            get
            {
                return secondName;
            }
            set
            {
                secondName = value;
            }
        }

        public override string ToString()
        {
            return string.Format("{0} {1}", firstName, secondName);
        }
    }
}
